clear all,clc,close all;
Uc(1)=0;
R=120;
C=33e-12;
U=5;
tau=R*C;
T=tau/100;
tmax=(4*tau);
t=0:T:tmax;
N=length(t);
stdn=3;
w=1e9;
Uvh(1)=sin(T*w);



for k=1:N;
    Uc=(U*T+Uc*R*C)/(C*R+2*T);
    Ur=U-2*Uc;
    Ucmas(k)=Uc;
end;
figure(1)
plot(t,Ucmas)


w=2*pi*(0:0.1/(tau):10/(tau));
% w=[0, 0.001*1/tau,  0.1*1/tau,  1/tau,  2/tau,  10*1/tau];

M=length(w);
for m=1:M; 
    
    for k=1:N*2
        Uvh=cos(k*w(m)*T);
        Uc=(Uvh*T+Uc*R*C)/(C*R+2*T);
        Ur=Uvh-2*Uc;
        Ucmas(k)=Uc;
    end
    
    U_save(m) = max(Ucmas(k-400:k));
    
end;
    
%     if t(k)<0;
%         Uvh(k)=0;
%     else 
%     end;
%     Uvih(k)=Uvh(k)/2;
%     K(m)=Uvih/Uvh;


figure(2)
plot(w/(2*pi),U_save)
% plot(w/(2*pi),K)
% ylim([0,1])
% xlabel('f,Hz')
% ylabel('K')


%На входе шум%
for k=2:N;
    Uvhw(k)=randn(1,1)*stdn;
    Uvihw(k)=Uvhw(k)/2;
end;
figure(3)
plot(t,Uvhw,t,Uvihw)
xlabel('t')
ylabel('Uvhw,Uvihw')
grid on


    
    